<?php

if (!defined('BASEPATH'))
exit('No direct script access allowed');

function admin_url() {
	return  base_url()."admin/";
}

function page404() {
	return base_url() . '404.html';
}

function theme_url($uri = '') {
	return base_url() . 'template/theme1/' . $uri;
}

function admin_theme_url($uri = '') {
	return base_url() . 'template/admin/' . $uri;
}

function prd() {
	echo "<pre style='clear: both; border-top: 1px solid red;'>";
	if (func_get_args()) foreach (func_get_args() as $item) {
		print_r($item);
		echo "<hr />";
	}
	
	$bt = debug_backtrace();
	$caller = array_shift($bt);
	echo "<div style='color:red' >Call from line <strong>".$caller['line'] . "</strong> file " . $caller['file'] ." on server: ".$_SERVER['SERVER_ADDR']."</div>";
	echo "</pre>";
	die();
}

function category_url($term, $page = 0)
{
	$ci = get_instance();
	$ci->load->model('Category_term_model', 'category');
	$url = base_url();
	$url = $url.$ci->category->get_slug($term->term_id).'/';
	if($page >1)
		$url = $url .'trang-'.$url.'.html';
	return $url ;
}


function event_url($term, $page = 0)
{
	$ci = get_instance();
	$ci->load->model('Event_term_model', 'event');
	$url = base_url();
	$url = $url . 'su-kien/' . $ci->event->get_slug($term->term_id).'/';
	if($page >1)
		$url = $url .'trang-'.$url.'.html';
	return $url ;
}


function term_url($term,$page = 0){
	$func = $term->term_type.'_url';
	if(function_exists($func))
		return call_user_func_array($func, array($term,$page));
}

function post_url($post)
{
	$ci = get_instance();
	$ci->load->model('Category_term_model', 'category');
	$url = base_url();
	if(isset($post->cat_id))
		$url = $url.$ci->category->get_slug($post->cat_id).'/';
	if(isset($post->post_slug))
		$url = $url.$post->post_slug.'-'.$post->post_id.'.html';
	return $url;
}

function image($path = '', $name = '')
{
	if (strpos($path, 'ttp://') || strpos($path, 'ttps://'))
		return $path;
	if($name == 'original')
		return base_url() . $path;
	$ci = get_instance();
	$image_size = $ci->config->item('image_sizes');
	$width = 60;
	$height = 60;
	if(isset($image_size[$name])){
		$width = $image_size[$name][0];
		$height = $image_size[$name][1];
	}
	$path = str_replace(basename($path),$width."x".$height.'-'.basename($path),$path);
	$path = str_replace('images/','image/',$path);
	return base_url() . $path;
}

function array_merge_key($array_1 = array(), $array_default = array())
{
	$arr_temp = array_merge($array_default, $array_1);
	return array_intersect_key($arr_temp, $array_default);
}

?>